home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / ghostscript / 8.64 / Resource / Init / gs_dps2.ps < prev    next >
Encoding:
Text File  |  2009-04-17  |  7.9 KB  |  248 lines

  1. %    Copyright (C) 1990, 1996, 1997, 1998, 2000 Aladdin Enterprises.  All rights reserved.
  2. % This software is provided AS-IS with no warranty, either express or
  3. % implied.
  4. % This software is distributed under license and may not be copied,
  5. % modified or distributed except as expressly authorized under the terms
  6. % of the license contained in the file LICENSE in this distribution.
  7. % For more information about licensing, please refer to
  8. % http://www.ghostscript.com/licensing/. For information on
  9. % commercial licensing, go to http://www.artifex.com/licensing/ or
  10. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. % San Rafael, CA  94903, U.S.A., +1(415)492-9861.
  12.  
  13. % $Id: gs_dps2.ps 8954 2008-08-08 04:22:38Z ray $
  14. % Initialization file for basic Display PostScript functions
  15. % that are also included in Level 2.
  16.  
  17. level2dict begin
  18.  
  19. % ------ Errors ------ %
  20.  
  21. % These errors are only defined in Level 2 and DPS.
  22. { /configurationerror /undefinedresource /unregistered }
  23. { .registererror } forall
  24.  
  25. % ------ Halftones ------ %
  26.  
  27. /.makestackdict
  28.     { { counttomark -1 roll } forall .dicttomark
  29.     } bind def
  30. /currenthalftone        % - currenthalftone <dict>
  31.     { mark .currenthalftone
  32.        { { exch pop }        % halftone
  33.          { /HalftoneType 1        % screen
  34.         { /Frequency /Angle /SpotFunction }
  35.            .makestackdict readonly
  36.          }
  37.          { /HalftoneType 2        % colorscreen
  38.         { /RedFrequency /RedAngle /RedSpotFunction
  39.           /GreenFrequency /GreenAngle /GreenSpotFunction
  40.           /BlueFrequency /BlueAngle /BlueSpotFunction
  41.           /GrayFrequency /GrayAngle /GraySpotFunction
  42.         }
  43.            .makestackdict readonly
  44.          }
  45.        }
  46.       exch get exec
  47.     } odef
  48. % Define sethalftone so it converts types 1-4 to type 5.
  49. /.makehalftoneRGBV {    % <dict> <type> <keys> <keysRGBV>
  50.   4 -1 roll exch { 1 index exch get exch } forall 15 1 roll
  51.   14 -2 roll mark 15 1 roll { /Gray /Blue /Green /Red } {
  52.         % stack: v0 v1 v2 type keys comp
  53.     mark
  54.     2 index 0 get 8 -1 roll
  55.     4 index 1 get 9 -1 roll
  56.     6 index 2 get 10 -1 roll
  57.         % stack: type keys comp mark k0 v0 k1 v1 k2 v2
  58.     /HalftoneType 10 index .dicttomark
  59.     counttomark 2 roll
  60.   } forall pop pop
  61.   /Default 1 index .dicttomark exch pop { .sethalftone5 }
  62. } bind def
  63.  
  64. % The value of each entry in .halftonetypes is a procedure:
  65. %    <setdict> <htdict> <<proc>> <setdict'> <htdict'> <sethalftoneproc>
  66. % This allows us to use these procedures both for actually implementing
  67. % sethalftone and for converting subsidiary dictionaries of HalftoneType 5
  68. % halftones.
  69. systemdict begin
  70. 15 dict /.halftonetypes 1 index def begin
  71.   1 {
  72.     mark exch /Default exch .dicttomark { .sethalftone5 }
  73.   } bind def
  74.   2 {
  75.     1 { /Frequency /Angle /SpotFunction } {
  76.       /RedFrequency /RedAngle /RedSpotFunction
  77.       /GreenFrequency /GreenAngle /GreenSpotFunction
  78.       /BlueFrequency /BlueAngle /BlueSpotFunction
  79.       /GrayFrequency /GrayAngle /GraySpotFunction
  80.     } .makehalftoneRGBV
  81.   } bind def
  82.   3 {
  83.     mark exch /Default exch .dicttomark { .sethalftone5 }
  84.   } bind def
  85.   4 {
  86.     3 { /Width /Height /Thresholds } {
  87.       /RedWidth /RedHeight /RedThresholds
  88.       /GreenWidth /GreenHeight /GreenThresholds
  89.       /BlueWidth /BlueHeight /BlueThresholds
  90.       /GrayWidth /GrayHeight /GrayThresholds
  91.     } .makehalftoneRGBV
  92.   } bind def
  93.   5 {
  94.     pop dup length dict copy
  95.     mark 1 index {
  96.         % Even HalftoneType 5 dictionaries have entries other than
  97.         % subsidiary halftone dictionaries.
  98.       dup type /dicttype ne {
  99.     0
  100.       } {
  101.     dup /HalftoneType .knownget not { 0 } if
  102.       } ifelse dup 5 gt {
  103.         % Stack: dict mark ... keyN dictN httypeN
  104.         % Assume that all HalftoneTypes > 5 convert to 5.
  105.     1 index 3 1 roll
  106.     //.halftonetypes exch get exec pop /Default get
  107.         % Stack: dict mark ... keyN setdict'N htdict'N
  108.     counttomark 1 add index 3 index 4 -1 roll put
  109.       } {
  110.     pop
  111.       } ifelse
  112.     } forall .dicttomark { .sethalftone5 }
  113.   } bind def
  114. end
  115. end
  116. /sethalftone {        % <dict> sethalftone -
  117.     % We must create the new dictionary in the same VM as the
  118.     % operand; otherwise, invalidaccess errors may occur.
  119.   .currentglobal 1 .argindex dup gcheck .setglobal
  120.   dup //.halftonetypes 1 index /HalftoneType get
  121.   dup type /integertype ne {
  122.     /sethalftone .systemvar /typecheck signalerror
  123.   } if
  124.   .knownget not {
  125.     /sethalftone .systemvar /rangecheck signalerror
  126.   } if
  127.   exec exec
  128.   .setglobal pop
  129. } .bind odef
  130. % Redefine setscreen and setcolorscreen to recognize halftone dictionaries,
  131. % and to insert the Frequency and Angle into Type 1 halftones, per
  132. % Adobe TN 5085.
  133. /.fixsethalftonescreen        % <freq> <angle> <dict> .fix...screen
  134.                 %   <freq> <angle> <dict> <dict'>
  135.  { dup dup /HalftoneType get 1 eq
  136.     { dup wcheck not { dup length .copydict } if
  137.       dup /Frequency 5 index put
  138.       dup /Angle 4 index put
  139.       languagelevel 3 ge { dup /AccurateScreens dup getuserparam put } if
  140.     }
  141.    if
  142.  } bind def
  143. /setscreen        % <ignore*2> <dict> setscreen -
  144.     { dup type /dicttype eq
  145.        { .fixsethalftonescreen sethalftone pop pop pop }
  146.        { //setscreen }
  147.       ifelse
  148.     } .bind odef
  149. /setcolorscreen        % <ignore*11> <dict> setcolorscreen -
  150.     { dup type /dicttype eq
  151.        { .fixsethalftonescreen sethalftone 12 { pop } repeat }
  152.        { //setcolorscreen }
  153.       ifelse
  154.     } .bind odef
  155. % Redefine currentscreen and currentcolorscreen to extract the Frequency
  156. % and Angle from Type 1 halftones, per Adobe TN 5085.
  157. /.fixcurrenthalftonescreen    % <dict> .fix... <freq> <angle> <proc>
  158.  { dup /HalftoneType get 1 eq
  159.     { dup /Frequency get 1 index /Angle get }
  160.     { 60.0 0.0 }    % Adobe returns these as reals
  161.    ifelse 3 2 roll
  162.  } bind def
  163. /currentscreen        % - currentscreen 60 0 <dict>
  164.     { .currenthalftone
  165.        { { .fixcurrenthalftonescreen }    % halftone
  166.          { }                % screen
  167.          { 12 3 roll 9 { pop } repeat    % colorscreen
  168.            dup type /dicttype eq { .fixcurrenthalftonescreen } if
  169.          }
  170.        }
  171.       exch get exec
  172.     } odef
  173. /currentcolorscreen    % - currentcolorscreen (60 0 <dict>)*4
  174. { .currenthalftone
  175.    { { .fixcurrenthalftonescreen 3 copy 6 copy }    % halftone
  176.      {                    % screen
  177.      % The procedure might not be readable....
  178.      dup rcheck { dup length array copy cvx } if
  179.      3 copy 6 copy
  180.      }
  181.      { }                % colorscreen
  182.    }
  183.   exch get exec
  184. } odef
  185.  
  186. % ------ User objects ------ %
  187.  
  188. /.UserObjects {
  189.   .userdict /UserObjects
  190. } odef
  191. % In order to get proper error recovery behavior, we need to be careful
  192. % not to pop any operands from the stack until we're done.
  193. % The code below faithfully duplicates the apparent array-growing
  194. % behavior of Adobe interpreters.
  195. /defineuserobject {        % <index> <value> defineuserobject -
  196.   1 index 65535 gt {
  197.     % .localvmarray throws limitcheck but CET 31-02 wants rangecheck
  198.     /defineuserobject .systemvar /rangecheck signalerror 
  199.   } if
  200.   .UserObjects .knownget {
  201.     length dup 3 .argindex le {
  202.         % Stack: index value len
  203.       2 index eq { 1 index 2 mul } { 1 index 1 add } ifelse
  204.       .localvmarray .UserObjects get
  205.       1 index copy pop
  206.       .UserObjects 3 -1 roll put
  207.     } {
  208.       pop
  209.     } ifelse
  210.   } {
  211.     .UserObjects 3 .argindex 1 add 10 .max .localvmarray put
  212.   } ifelse
  213.   .UserObjects get 2 .argindex 2 index put pop pop
  214. } odef
  215. /execuserobject {        % <index> execuserobject -
  216.   dup type /integertype ne {
  217.     % Adobe validates the argument before accessing UserObjects - CET 31-03 
  218.     /execuserobject .systemvar /typecheck signalerror 
  219.   } if
  220.   .UserObjects get 1 .argindex get exch pop exec
  221. } odef
  222. /undefineuserobject {        % <index> undefineuserobject -
  223.   dup type /integertype ne {
  224.     % Adobe validates the argument before accessing UserObjects - CET 31-11 
  225.     /undefineuserobject .systemvar /typecheck signalerror
  226.   } if
  227.   .UserObjects get 1 .argindex //null put pop
  228. } odef
  229.  
  230. % ------ Cache control ------ %
  231.  
  232. % Dummy definitions for cache control operators
  233.  
  234. /ucachestatus {            % - ucachestatus -mark- ? ? ? ? <size>
  235.     mark 0 0 0 0 /MaxUPathItem getuserparam
  236. } odef
  237. /setucacheparams {        % -mark- ... <size> setucacheparams -
  238.         % Provoke an appropriate error if needed.
  239.     counttomark 1 lt { () 0 get } if
  240.     dup 0 or /MaxUPathItem getuserparam .max
  241.         1 dict dup /MaxUPathItem 4 -1 roll put setuserparams cleartomark
  242. } odef
  243.  
  244. end                % level2dict
  245.